package com.eclink.asset.asset.handler;


import com.eclink.asset.asset.domain.dao.FlowApply;
import com.eclink.asset.asset.service.AssetItemService;
import com.eclink.asset.enums.ApplyStateEnum;
import com.eclink.asset.workflow.enums.TodoTypeEnum;
import com.eclink.asset.workflow.handler.ApplyFinishHandler;
import com.eclink.asset.workflow.mapper.FlowApplyMapper;
import com.eclink.asset.workflow.service.TodoService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Component
public class EmployeeAssetApplyReceiveHandler implements ApplyFinishHandler {

    @Resource
    private FlowApplyMapper flowApplyMapper;

    @Resource
    private AssetItemService assetItemService;

    @Resource
    private TodoService todoService;

    @Transactional
    public void execute(String id) {
        FlowApply flowApply = flowApplyMapper.selectById(id);
        flowApply.setUpdateTime(LocalDateTime.now());
        flowApply.setState(ApplyStateEnum.TO_HANDLE.getValue());
        flowApplyMapper.updateById(flowApply);

        // 增加用户申请的待办
        todoService.createTodo(flowApply, TodoTypeEnum.EMPLOYEE.getValue());
    }

    @Override
    public void reject(String id) {

    }

}
